Return to start page

Systems/Character/Struct Kill Quest Item.j

Code

		
1			library AStructSystemsCharacterKillQuestItem requires ALibraryCoreStringConversion, AStructSystemsCharacterQuest

2
3 /// @state untested
4 struct AKillQuestItem extends AQuestItem
5 //static start members
6 private static string message
7 //start members
8 private integer m_unitTypeId
9 private integer m_targetUnitTypeId
10 private integer m_count
11 //members
12 private integer m_killed
13
14 //start members
15
16 public method unitTypeId takes nothing returns integer
17 return this.m_unitTypeId
18 endmethod
19
20 public method targetUnitTypeId takes nothing returns integer
21 return this.m_targetUnitTypeId
22 endmethod
23
24 public method count takes nothing returns integer
25 return this.m_count
26 endmethod
27
28 //members
29
30 public method killed takes nothing returns integer
31 return this.m_killed
32 endmethod
33
34 private method stateEventCompleted takes thistype questItem, trigger whichTrigger returns nothing
35 call TriggerRegisterAnyUnitEventBJ(whichTrigger, EVENT_PLAYER_UNIT_DEATH)
36 endmethod
37
38 private method stateConditionCompleted takes thistype questItem returns boolean
39 local unit killer
40 local unit triggerUnit
41 local boolean result = true
42 if (questItem.m_unitTypeId != 0) then
43 set killer = GetKillingUnit()
44 set result = GetUnitTypeId(killer) == questItem.m_unitTypeId
45 set killer = null
46 endif
47 if (result and questItem.m_targetUnitTypeId != 0) then
48 set triggerUnit = GetTriggerUnit()
49 set result = GetUnitTypeId(triggerUnit) == questItem.m_targetUnitTypeId
50 set triggerUnit = null
51 endif
52 if (result) then
53 set questItem.m_killed = questItem.m_killed + 1
54 call questItem.quest().displayUpdateMessage(IntegerArg(IntegerArg(thistype.message, questItem.m_killed), questItem.m_count))
55 endif
56 return questItem.m_killed == questItem.m_count
57 endmethod
58
59 /**
60 * @param unitTypeId If this value is 0 all unit types can kill the target unit type.
61 * @param targetUnitTypeId If this value is 0 all unit types can be killed by an unit-type unit.
62 */
63 public static method create takes AQuest usedQuest, string description, integer unitTypeId, integer targetUnitTypeId, integer count returns thistype
64 local thistype this = thistype.allocate(usedQuest, description)
65 //start members
66 set this.m_unitTypeId = unitTypeId
67 set this.m_targetUnitTypeId = targetUnitTypeId
68 set this.m_count = count
69 //members
70 set this.m_killed = 0
71
72 call this.setStateEvent(AAbstractQuest.stateCompleted, thistype.stateEventCompleted)
73 call this.setStateCondition(AAbstractQuest.stateCompleted, thistype.stateConditionCompleted)
74 return this
75 endmethod
76
77 public static method init0 takes string message returns nothing
78 //static start members
79 set thistype.message = message
80 endmethod
81 endstruct
82
83 endlibrary